package com.ruoyi.common.config.serializer;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;
import java.sql.Time;

public class SqlTimeDeserializer extends JsonDeserializer {
    @Override
    public Object deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {

        String time = jsonParser.getValueAsString();
        String[] times = time.split(":");
        switch (times.length){
           case  0: return  Time.valueOf("00:00:00");
           case  1: return  Time.valueOf( time + ":00:00");
           case  2: return  Time.valueOf( time + ":00");
           case  3: return  Time.valueOf(time);
           default: return  Time.valueOf(times[0] + ":" + times[1] + ":" + times[2]);
        }
    }
}
